package com.weizai.carshop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.entiity.GoodsProduct;
import com.weizai.carshop.model.entiity.ShopClassEntity;
import com.weizai.carshop.model.entiity.ShopInfoList;
import com.weizai.carshop.model.entiity.SlideshowEntity;
import com.weizai.carshop.service.GoodsProductListService;
import com.weizai.carshop.service.HomeService;
import com.weizai.carshop.service.ShopClassService;
import com.weizai.carshop.service.ShopInfoListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
public class Home {
    @Autowired
    private HomeService homeService;
    @Autowired
    private ShopClassService shopClassService;
    @Autowired
    private ShopInfoListService shopInfoListService;
    @Autowired
    private GoodsProductListService goodsProductListService;

    /**
     * 轮播图
     * @return
     */
    @GetMapping("/getSlideList")
    public ResponseResult getSlideList(){
        List<SlideshowEntity> list = homeService.list();
        return ResponseResult.okResult(list);
    }
    /**
     * 获取商品分类
     */
    @GetMapping("/getShopClass")
    public ResponseResult getShopClass(){
        List<ShopClassEntity> list = shopClassService.list();
        return ResponseResult.okResult(list);
    }
    /**
     * 获取商品列表
     */
    @GetMapping("/getShopList")
    @Cacheable(cacheNames = "shopListCache",key = "#type")
    public ResponseResult getShopList(@RequestParam(required = false,defaultValue = "1") Integer type){
        LambdaQueryWrapper<ShopInfoList> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ShopInfoList::getPidId, type);
        // 获取结果
        List<ShopInfoList> resultList = shopInfoListService.list(queryWrapper);
        // 返回查询结果
        return ResponseResult.okResult(resultList);
    }
    /**
     * 获取商品展示
     */
    @GetMapping("/getGoodsProduct")
    public ResponseResult getGoodsProduct(){
        List<GoodsProduct> list = goodsProductListService.list();
        return ResponseResult.okResult(list);
    }
}

